from operator import attrgetter

class Agent(object):
    """Base agent class to be overrided in order to create custom agents."""
    
    # TODO: modify agent editor so that it cannot edit read_only agents
    read_only = False
    
    _name = None
    
    def decide(self, my_id, info):
        """
        Return True if agent will invest in security for this round, False otherwise.
        Override this method to develop a custom agent.
        
        Keyword arguments:
        my_id -- id of agent in the current game.
        info -- an initialized Agentinfo object.
        """
        return True

    def name(self):
        return self.__class__.__name__.split('.')[-1]
        #return self._name if self._name else self.__class__.__name__.split('.')[-1]
    
class AgentSet(object):
    """
    A set of agents that may be loaded into a tournament. Defines the classes
    of agents in the tournament, but contains no information about relative
    frequencies.
    """
    def __init__(self, init_data=[]):
        self._data = set(init_data)
             
    def add_agent_class(self, agent_class):
        self._data.add(agent_class)
    
    def remove_agent_class(self, agent_class):
        self._data.remove(agent_class)
    
    def get_list(self):
        """Return agent classes as list sorted by class name."""
        return sorted(list(self._data),key=attrgetter('__name__'))
    
    def size(self):
        return len(self._data)
 